
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:gun/main.dart';

class DialogWidget {

  final RxInt _value = RxInt(5);

  settingDialog(){
    _value.value = settingEntity.power??5;
    Get.defaultDialog(
      title: "",
      contentPadding:EdgeInsets.zero,
      titlePadding:EdgeInsets.zero,
      backgroundColor: Colors.transparent,
      content: Container(
        width: 350.w,
        height: 250.h,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(6.r)),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('功率调整'),
            SizedBox(height: 20.h,),
            Obx(() => Slider(
              value: _value.value.toDouble(),
              min: 5.0,
              max: 30.0, onChanged: (double v) {
                _value.value = v.toInt();
            },)),
            Obx(() => Text('${_value.value.toInt()}'),),
            SizedBox(height: 20.h,),
            InkWell(
              onTap: (){
                settingEntity.power = _value.value;
                var box = GetStorage();
                box.write('setting_entity', settingEntity.toJson());
                _setPower(_value.value);
                Get.back();
              },
              child: Image.asset("assets/images/confirm.png",width: 150.w,fit: BoxFit.fitWidth,),
            )

          ],
        )
      ),
    );
  }

  _setPower(power) async {
    var result = await const MethodChannel('toAndroid').invokeMethod('setPower',power);
    print('setPower $result');
  }

}